using BlazorComponent;
using Masa.Blazor.Presets;
using Masa.Blazor;
using Microsoft.AspNetCore.Components.WebView.WindowsForms;
using Microsoft.Extensions.DependencyInjection;

namespace CodeGenerator;

public partial class MainFrom : Form
{
    public MainFrom()
    {
        InitializeComponent();

        var services = new ServiceCollection();
        services.AddWindowsFormsBlazorWebView();

        //MASA
        services.AddMasaBlazor(options =>
        {
            options.Locale = new Locale("zh-CN", "en-US");
            options.Defaults = new Dictionary<string, IDictionary<string, object?>?>()
    {
        {
            "MSelect", new Dictionary<string, object?>()
            {
                { "HideDetails", (StringBoolean)"auto" }
            }
        },
        {
            "MTextField", new Dictionary<string, object?>()
            {
                { "HideDetails", (StringBoolean)"auto" }
            }
        },
        {
            PopupComponents.SNACKBAR, new Dictionary<string, object?>()
            {
                { nameof(PEnqueuedSnackbars.Closeable), true },
                { nameof(PEnqueuedSnackbars.Position), SnackPosition.TopCenter },
                { nameof(PEnqueuedSnackbars.Timeout), 2000 }
            }
        }
    };
        });

        blazorWebView1.HostPage = "wwwroot/index.html";
        blazorWebView1.Services = services.BuildServiceProvider();
        blazorWebView1.RootComponents.Add<App>("#app");
    }

    private void MainFrom_FormClosed(object sender, FormClosedEventArgs e)
    {
        Environment.Exit(0);
    }
}
